
var kmcode;
var tcode;
function initLoading() {
   DWREngine.setPreHook(function() {
  	loading();
  });

  DWREngine.setPostHook(function() {
    remove_loadingdiv();
  });
}

function loading() {
	show_loadingpage();
}
var div_left = 0;
var div_right = 0;
var loading_constant = 0;
function move_loading() {
	var move_div = document.getElementById("move_div");
	var move_div_arry = new Array();
	move_div_arry[1] = document.getElementById("move_div1");
	move_div_arry[2] = document.getElementById("move_div2");
	move_div_arry[3] = document.getElementById("move_div3");
	move_div_arry[4] = document.getElementById("move_div4");
	move_div_arry[5] = document.getElementById("move_div5");
	if (div_left < 250) {
		move_div.style.left = div_left + "px";
		div_left += 5;
		div_right = 250;
	} else {
		if (div_right > -77) {
			for (i = 1; i < 6; i++) {
				move_div_arry[i].className = "move_div" + (6 - i);
			}
			move_div.style.left = div_right + "px";
			div_right -= 4;
		} else {
			div_left = -77;
			for (i = 1; i < 6; i++) {
				move_div_arry[i].className = "move_div" + i;
			}
		}
	}
}
function flicker_text() {
	var loading_text = document.getElementById("loading_text");
	if (loading_constant == 0) {
		loading_text.style.color = "#4e7f31";
		loading_constant = 1;
	} else {
		loading_text.style.color = "#000000";
		loading_constant = 0;
	}
}
function show_loadingpage() {
	var cover_div = document.createElement("div");
	cover_div.id = "cover_divone";
	cover_div.style.height = "100%";
	cover_div.style.width = "100%";
	cover_div.style.position = "absolute";
	cover_div.style.left = "0";
	cover_div.style.top = "0";
	cover_div.style.zIndex = "3000";
	cover_div.innerHTML = "<iframe scrolling=\"no\" frameborder=\"0\" width=\"100%\" height=\"100%\" style=\"z-index:3000;\"></iframe>";
	cover_div.style.filter='alpha(opacity=1)';
	cover_div.style.opacity='0.1';
	var cover_div2 = document.createElement("div");
	cover_div2.id = "cover_divtwo";
	cover_div2.style.height = "100%";
	cover_div2.style.width = "100%";
	cover_div2.style.position = "absolute";
	cover_div2.style.left = "0";
	cover_div2.style.top = "0";
	cover_div2.style.zIndex = "3010";
	cover_div2.style.background = "#ffffff";
	cover_div2.style.filter='alpha(opacity=3)';
	cover_div2.style.opacity='0.3';
	var load_div = document.createElement("div");
	load_div.id = "load_div";
	load_div.style.height = "100%";
	load_div.style.width = "100%";
	load_div.style.position = "absolute";
	load_div.style.left = "0";
	load_div.style.top = "0";
	load_div.style.zIndex = "3100";	
	//load_div.style.textAlign='center';
	load_div.style.paddingTop = document.body.offsetHeight / 2 - 50 + "px";
	load_div.style.paddingLeft = document.body.offsetWidth / 2 - 100 + "px";
	document.body.appendChild(cover_div);
	document.body.appendChild(cover_div2);
	document.body.appendChild(load_div);
	load_div.innerHTML = "<div class=\"border_div\" id=\"border_div\"><div id=\"move_div\"><div class=\"move_div5\" id=\"move_div5\"></div><div class=\"move_div4\" id=\"move_div4\"></div><div class=\"move_div3\" id=\"move_div3\"></div><div class=\"move_div2\" id=\"move_div2\"></div><div class=\"move_div1\" id=\"move_div1\"></div></div></div><p id=\"loading_text\" style=\"margin:0 0 0 80px \">\u6b63\u5728\u52a0\u8f7d\u6570\u636e\uff0c\u8bf7\u7a0d\u5019......</p>";
	setInterval(move_loading, 50);
	setInterval(flicker_text, 500);
}
function remove_loadingdiv(){
	var cover_divone = document.getElementById("cover_divone");
	var cover_divtwo = document.getElementById("cover_divtwo");
	var load_div = document.getElementById("load_div");
	document.body.removeChild(cover_divone);
	document.body.removeChild(cover_divtwo);
	document.body.removeChild(load_div);
}



function init() {
	initLoading();
	DWREngine.setTimeout(5000);
}
function getKc(kmobj, tid) {
	kmcode = kmobj;
	tcode = tid;
	kcDwr.getSchoolCourse(kmSelect);
}
function kmSelect(data) {
	DWRUtil.removeAllOptions("kmSelect");
	DWRUtil.addOptions("kmSelect", {"":"\u8bf7\u9009\u62e9\u79d1\u76ee"});
	DWRUtil.addOptions("kmSelect", data);
	selectKmOption(kmcode);
	getKmTearcherMap();
}
function selectKmOption(kmobj) {
	if (null != kmobj) {
		DWRUtil.setValue("kmSelect", kmobj);
	}
}
function getTearList() {
	var km = document.getElementById("kmSelect").value;
	kcDwr.getTeacherCourseList(km, TearchCheckBoxList);
}
function TearchCheckBoxList(data) {
	var tabone = document.getElementById("tab");
	var tab = "<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border:1px solid #d7d7d7'>";
	var tabbody = "";
	if (null != data && "" != data) {
		var list = "<tr>";
		for (i = 0; i < data.length; i++) {
			if ((i + 1) % 6 == 0) {
				list += "<td><table border='0' cellspacing='4' cellpadding='0'><tr> <td><input type='checkbox' name='teacherid' value='" + data[i].rkjs;
				if ("Y" == data[i].isUsed) {
					list += "' checked='checked'></td><td>" + data[i].tearcherName + "</td></tr></table></td></tr><tr>";
				} else {
					list += "'></td><td>" + data[i].tearcherName + "</td></tr></table></td></tr><tr>";
				}
			} else {
				if (i == data.length - 1) {
					for (j = 0; j < 6 - data.length % 6; j++) {
						list += "<td><table border='0' cellspacing='4' cellpadding='0'><tr></tr></table></td>";
					}
					list += "<td><table border='0' cellspacing='4' cellpadding='0'><tr> <td><input type='checkbox' name='teacherid' value='" + data[i].rkjs;
					if ("Y" == data[i].isUsed) {
						list += "' checked='checked'></td><td>" + data[i].tearcherName + "</td></tr></table></td></tr>";
					} else {
						list += "'></td><td>" + data[i].tearcherName + "</td></tr></table></td></tr>";
					}
				} else {
					list += "<td><table border='0' cellspacing='4' cellpadding='0'><tr> <td><input type='checkbox' name='teacherid' value='" + data[i].rkjs;
					if ("Y" == data[i].isUsed) {
						list += "' checked='checked'></td><td>" + data[i].tearcherName + "</td></tr></table></td>";
					} else {
						list += "'></td><td>" + data[i].tearcherName + "</td></tr></table></td>";
					}
				}
			}
		}
		tabbody = list;
	}
	tabone.innerHTML = tab + tabbody;
}
function getKmTearcherMap() {
	var km = document.getElementById("kmSelect").value;
	kmcode = km;
	if (null != km && "" != km) {
		kcDwr.getKmTeacher(km, TearSelectMap);
	}
}
function TearSelectMap(data) {
	DWRUtil.removeAllOptions("tearcherSelect");
	DWRUtil.addOptions("tearcherSelect", {"":"\u8bf7\u9009\u62e9\u6559\u5e08"});
	DWRUtil.addOptions("tearcherSelect", data);
	tearSelectOption(kmcode, tcode);
}
function tearSelectOption(km, tid) {
	if (null != km) {
		DWRUtil.setValue("kmSelect", km);
	}
	if (null != tcode) {
		DWRUtil.setValue("tearcherSelect", tid);
	}
}
function delKb(kbid, obj) {
	kcDwr.DelOneKB(kbid, DelKbResult);
	clearkc(obj);
}
function DelKbResult(data) {
	alert(data);
}
function getTeacherKm(tid, kmid) {
	//DWREngine.setAsync(false);
	kcDwr.getKmByTeacherID(tid, TeacherKMOption);
	kmcode = kmid;
}
function TeacherKMOption(data) {
	DWRUtil.removeAllOptions("kmSelect");
	DWRUtil.addOptions("kmSelect", {"":"\u8bf7\u9009\u62e9\u79d1\u76ee"});
	DWRUtil.addOptions("kmSelect", data);
	TeacherKmSelect(kmcode);
}
function TeacherKmSelect(kmid) {
	if (null != kmid && "" != kmid) {
		DWRUtil.setValue("kmSelect", kmid);
	}
}
function getKm(tid, tName) {
	tcode = tid;
	if (null != tName) {
		document.getElementById("tchvalue").value = tName;
	}
	kcDwr.getSchoolCourse(kmSOption);
}
function kmSOption(data) {
	DWRUtil.removeAllOptions("km");
	DWRUtil.addOptions("km", {"":"\u8bf7\u9009\u62e9\u79d1\u76ee"});
	DWRUtil.addOptions("km", data);
	getKmTeacherCheck();
}
function getKmTeacherCheck() {
	var km = document.getElementById("km").value;
	kcDwr.getKmTeacherCheck(km, TeacherCheckList);
}
function TeacherCheckList(data) {
	var tabone = document.getElementById("tab");
	var th = "<table width='100%' border='0' cellpadding='0' cellspacing='0'>";
	var tf = "</table>";
	var tabbody = "";
	if (null != data && "" != data) {
		var list = "<tr>";
		for (i = 0; i < data.length; i++) {
			if ((i + 1) % 6 == 0) {
				list += "<td align='center'><a onClick=\"setTchValue(this,'xzjs');setTidValue('" + data[i].teacherid + "')\">" + data[i].xm + "</a></td></tr>";
			} else {
				if (i == data.length - 1) {
					list += "<td align=\"center\"><a onClick=\"setTchValue(this,'xzjs');setTidValue('" + data[i].teacherid + "')\">" + data[i].xm + "</a></td>";
					for (j = 0; j < 6 - data.length % 6; j++) {
						list += "<td align=\"center\">&nbsp;</td>";
					}
					list += "</tr>";
				} else {
					list += "<td align='center'><a onClick=\"setTchValue(this,'xzjs');setTidValue('" + data[i].teacherid + "')\">" + data[i].xm + "</a></td>";
				}
			}
		}
		tabbody = list;
	}
	tabone.innerHTML = th + tabbody + tf;
}
function setTidValue(obj) {
	if (null != obj) {
		document.getElementById("tid").value = obj;
	}
}

